<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #operationBeforeExtend="{record}">
        <a-link @click="handleDetail(record)">详情</a-link>
        <a-popconfirm content="是否确定复制？" @ok="handleClone(record)">
          <a-link >一键复制</a-link>
        </a-popconfirm>
        
        <a-link @click="handleTemplateDetail(record)">费用模版配置</a-link>
      </template>
    </ma-crud>

    <a-drawer :footer="false" :width="1400" v-model:visible="visibleCharging">
			<template #title> 费用模版配置 </template>
			<templateDetail ref="userContractChargingRef" :inforows="inforows" v-if="visibleCharging"/>
		</a-drawer>

    <!-- 详情 -->
		<a-modal :mask-closable="false"  v-model:visible="detailShow" title="模版详情" :width="1400" :footer="false">
			<templateDetailes v-if="detailShow" :formData="formData"></templateDetailes>
		</a-modal>

  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import systemTemplate from '@/api/system/systemTemplate'
import templateDetail from "@/views/system/templateDetail/index.vue";
import templateDetailes from "@/views/system/template/detail.vue";
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()
const inforows = ref({})
const visibleCharging = ref(false)
const detailShow = ref(false)
const formData = ref({})
const handleTemplateDetail = (row) =>{
  inforows.value = row
  visibleCharging.value = true
}
const handleDetail = (row)=>{
		formData.value = row
		setTimeout(()=>{
			detailShow.value = true
		},200)
		
}
const handleClone = (row)=>{
  systemTemplate.getcopy(row.id,{}).then(res=>{
    Message.success('复制成功')
    crudRef.value.refresh()
  })
  
}

const numberOperation = (newValue, id, numberName) => {
  systemTemplate.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  systemTemplate.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'flyos_system_template',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: systemTemplate.getList,
  recycleApi: systemTemplate.getRecycleList,
  add: {
    show: true,
    api: systemTemplate.save,
    auth: ['system:template:save']
  },
  edit: {
    show: true,
    api: systemTemplate.update,
    auth: ['system:template:update']
  },
  delete: {
    show: true,
    api: systemTemplate.deletes,
    auth: ['system:template:delete'],
    realApi: systemTemplate.realDeletes,
    realAuth: ['system:template:realDeletes']
  },
  recovery: {
    show: true,
    api: systemTemplate.recoverys,
    auth: ['system:template:recovery']
  },
  import: {
    show: true,
    url: 'system/template/import',
    templateUrl: 'system/template/downloadTemplate',
    auth: ['system:template:import']
  },
  export: {
    show: true,
    url: 'system/template/export',
    auth: ['system:template:export']
  }
})

const columns = reactive([
  {
    title: "id",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入id"
    }
  },
  {
    title: "模版名称",
    dataIndex: "name",
    formType: "input",
    search: true
  },
  {
    title: "开始时间",
    dataIndex: "start_time",
    formType: "date",
    search: true,
    showTime: false
  },
  {
    title: "结束时间",
    dataIndex: "end_time",
    formType: "date",
    search: true,
    showTime: false
  },
  {
    title: "状态",
    dataIndex: "status",
    formType: "select",
    search: true,
    dict: {
      data: [
        {
          label: "启用",
          value: "1"
        },
        {
          label: "禁用",
          value: "2"
        }
      ],
      translation: true
    }
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  }
])
</script>
<script> export default { name: 'system:template' } </script>